/*******************************************************************\
| CudaUtils.h
|
| CREATED:		20.6.2009
| DESCRIPTION:
| 
| CUDA Util functions
\********************************************************************/
#ifndef CUDAUTILS_H
#define CUDAUTILS_H

//Round a / b to nearest higher integer value
int IntDivUp(int a, int b);

// compute grid and thread block size for a given number of elements
extern "C" void ComputeGridSize(int n, int blockSize, int &numBlocks, int &numThreads);

// compute grid size dimensions
extern "C" void ComputeGridSizeDim(int p_Elements, int p_ThreadsPerBlock, dim3& p_Blocks, dim3& p_Threads);

// checks for kernel execution errors
extern "C" void CudaCheckError(const char *errorMessage);

// starts recording memory allocation statistics
extern "C" void StartAllocationStats();

// cuda malloc/free wrapper for allocation statistics tracking
extern "C" cudaError_t CudaMallocRec(void **devPtr, size_t size);
extern "C" cudaError_t CudaFreeRec(void *devPtr);
extern "C" cudaError_t CudaMallocPitchRec(void **devPtr, size_t *pitch, size_t width, size_t height);
extern "C" cudaError_t CudaMallocArrayRec(struct cudaArray **array, const struct cudaChannelFormatDesc *desc, size_t width, size_t height);
extern "C" cudaError_t CudaFreeArrayRec(struct cudaArray *array);

// stops recording of memory allocation statistics and prints a summary
extern "C" void EndAllocationStats();

#endif // CUDAUTILS_H
